package com.hung.web;

import com.hung.client.TestClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/4/20.
 */
@RestController
@RequestMapping("ribbon")
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private TestClient testClient;


    @RequestMapping(value ="/user",method = RequestMethod.GET)
    @HystrixCommand(fallbackMethod = "addServiceFallback")
    public  Object  test(){
        return restTemplate.getForEntity("http://USER-SERVICE/api/userController/getUser?userName=lihongming",String.class).getBody();
    }

    @RequestMapping(value ="/user1",method = RequestMethod.GET)
    public  Object  test1(){
        return  testClient.getUser("lihong");
    }

    public String addServiceFallback(){
        return "error";
    }
}
